#include "StdAfx.h"
#include ".\handler_cg_pvp.h"
#include ".\PVPManager.h"
#include ".\Player.h"
#include ".\GamePVPRoom.h"

Handler_CG_PVP::Handler_CG_PVP(void)
{
}

Handler_CG_PVP::~Handler_CG_PVP(void)
{
}

Handler_CG_PVP_IMPL(CG_PVP_PRESS_KEY_SYN)
{
	MSG_CG_PVP_PRESS_KEY_SYN * pRecvMsg = (MSG_CG_PVP_PRESS_KEY_SYN *)pMsg;

	DWORD UserKey = pRecvMsg->m_dwKey;
	Player *pPlayer = PlayerManager::Instance()->FindPlayer( UserKey );
	ASSERT( pPlayer );
	if( !pPlayer ) return;

	GameZone * pEnterZone	= NULL;
	CODETYPE EnterFieldCode	= 0;
	eZONE_STATE eState		= pPlayer->GetGameZone( pEnterZone, EnterFieldCode );
	if( !(eState & ePRS_AT_ZONE) )
	{
		MSG_CG_PVP_PRESS_KEY_NAK msg;
		msg.m_byErrorCode = RC::RC_PVP_NOT_AT_ZONE;
		pPlayer->SendPacket( &msg, sizeof(msg) );
		return;
	}

	GamePVPRoom * pPVPRoom = (GamePVPRoom *)pEnterZone;
	RC::ePVP_RESULT rt = pPVPRoom->GetPVPManager()->PressKeyPlayer( pPlayer );
	if( rt == RC::RC_PVP_SUCCESS )
	{
		MSG_CG_PVP_PRESS_KEY_ACK msg;
		pPlayer->SendPacket( &msg, sizeof(msg) );
	}
	else
	{
		MSG_CG_PVP_PRESS_KEY_NAK msg;
		msg.m_byErrorCode = rt;
		pPlayer->SendPacket( &msg, sizeof(msg) );
	}

}